package cn.wh.executor.result;

import cn.wh.reflection.factory.ObjectFactory;
import cn.wh.session.ResultContext;
import cn.wh.session.ResultHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wh
 * @Description
 * @Date 2023/6/25 9:11
 * @Version 1.0
 **/
public class DefaultResultHandler implements ResultHandler {


    private final List<Object> list;


    public DefaultResultHandler() {
        this.list = new ArrayList<>();
    }

    @SuppressWarnings("unchecked")
    public DefaultResultHandler(ObjectFactory objectFactory) {
        this.list = objectFactory.create(List.class);
    }

    @Override
    public void handleResult(ResultContext context) {
        list.add(context.getResultObject());
    }

    public List<Object> getResultList() {
        return list;
    }
}
